package com.smart.village.big.screen.controller.change;

import com.smart.village.big.screen.domain.AjaxResult;
import com.smart.village.big.screen.service.ChangeBenefitPeopleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.logging.Logger;

import static com.smart.village.big.screen.domain.AjaxResult.error;
import static com.smart.village.big.screen.domain.AjaxResult.success;

/**
 * 新修改-数智农业数据接口
 */
@Tag(name = "新修改-数智农业数据接口")
@RestController
@RequestMapping("/change/benefit/people")
public class ChangeBenefitPeopleController {
    @Autowired
    private ChangeBenefitPeopleService changeBenefitPeopleService;
    Logger logger = Logger.getLogger(ChangeBenefitPeopleController.class.getName());

    /**
     * 惠民数据-村两委信息
     */
    @Operation(summary = "惠民数据-村两委信息")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传")
    })
    @GetMapping("/getVillageTwoLeaderInfo")
    @ResponseBody
    public AjaxResult getVillageTwoLeaderInfo(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false, defaultValue = "") String villageNumber
    ) {
        try {
            return success(changeBenefitPeopleService.getVillageTwoLeaderInfo(townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据-村民诉求统计
     */
    @Operation(summary = "惠民数据-村民诉求统计")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传")
    })
    @GetMapping("/getVillagePeopleComplainInfo")
    @ResponseBody
    public AjaxResult getVillagePeopleComplainInfo(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false, defaultValue = "") String villageNumber
    ) {
        try {
            return success(changeBenefitPeopleService.getVillagePeopleComplainInfo(townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据-诉求处理情况
     */
    @Operation(summary = "惠民数据-诉求处理情况")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
            @Parameter(name = "pageNum", description = "当前页数 非必传默认1"),
            @Parameter(name = "pageSize", description = "每页条数 非必传默认10")
    })
    @GetMapping("/getVillagePeopleComplainHandleInfo")
    @ResponseBody
    public AjaxResult getVillagePeopleComplainHandleInfo(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false, defaultValue = "") String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return success(changeBenefitPeopleService.getVillagePeopleComplainHandleInfo(townNumber, villageNumber,pageNum,pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据-村规村约
     */
    @Operation(summary = "惠民数据-村规村约")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传")
    })
    @GetMapping("/getVillageRegulationsAgreements")
    @ResponseBody
    public AjaxResult getVillageRegulationsAgreements(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false, defaultValue = "") String villageNumber
    ) {
        try {
            return success(changeBenefitPeopleService.getVillageRegulationsAgreements(townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
    /**
     * 惠民数据--政策宣传
     *
     * @return
     */
    @Operation(summary = "惠民数据--政策宣传 ")
    @GetMapping("/getPolicyAdvocacy")
    @ResponseBody
    public AjaxResult getPolicyAdvocacy(
            @RequestParam(required = false, defaultValue = "") String NewsTerminal,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
            pageNum = 1;
        }
        if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
            pageSize = 10;
        }
        return AjaxResult.success(changeBenefitPeopleService.getPolicyAdvocacy(pageNum, pageSize,NewsTerminal));
    }
    /**
     * 惠民数据--普法宣传
     *
     * @return
     */
    @Operation(summary = "惠民数据--普法宣传 ")
    @GetMapping("/getLawAdvocacy")
    @ResponseBody
    public AjaxResult getLawAdvocacy(
            @RequestParam(required = false, defaultValue = "") String NewsTerminal,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
            pageNum = 1;
        }
        if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
            pageSize = 10;
        }
        return AjaxResult.success(changeBenefitPeopleService.getLawAdvocacy(pageNum, pageSize,NewsTerminal));
    }
    /**
     * 惠民数据-中间三个标签的数据
     */
    @Operation(summary = "惠民数据-中间三个标签的数据")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传")
    })
    @GetMapping("/getCenterThreeData")
    @ResponseBody
    public AjaxResult getCenterThreeData(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false, defaultValue = "") String villageNumber
    ) {
        try {
            return success(changeBenefitPeopleService.getCenterThreeData(townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "村级事务-三务公开")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
            @Parameter(name = "type", description = "类型 必传  0:党务公开 1:财务公开 2:村务公开"),
    })
    @GetMapping("/getThreeAffairsDisclosureList")
    @ResponseBody
    public AjaxResult getThreeAffairsDisclosureList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) String type,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        return AjaxResult.success(changeBenefitPeopleService.getThreeAffairsDisclosureList(townNumber, villageNumber, type, pageNum, pageSize));
    }

    @Operation(summary = "村级事务-三务公开-详情")
    @Parameters({
            @Parameter(name = "affairsSerialNumber", description = "三务公开ID 必传"),
    })
    @GetMapping("/getThreeAffairsDisclosureDetail")
    @ResponseBody
    public AjaxResult getThreeAffairsDisclosureDetail(
            @RequestParam String affairsSerialNumber
    ) {
        return AjaxResult.success(changeBenefitPeopleService.getThreeAffairsDisclosureDetail(affairsSerialNumber));
    }

    @Operation(summary = "村级事务-三资公开")
    @GetMapping("/getThreeResourceInformationList")
    @ResponseBody
    @Parameters({
            @Parameter(name = "type", description = "类型 必传 【资产 资源 资金】"),
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
            @Parameter(name = "pageNum", description = "当前页数 非必传默认1"),
            @Parameter(name = "pageSize", description = "每页条数 非必传默认10")
    })
    public AjaxResult getThreeResourceInformationList(
            @RequestParam String type,
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getThreeResourceInformationList(type,townNumber, villageNumber, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "村级事务-村级清单-列表")
    @Parameters({
            @Parameter(name = "listTypeSerialNumber", description = "清单类型ID"),
            @Parameter(name = "townNumber", description = "镇id"),
            @Parameter(name = "villageNumber", description = "村id"),
            @Parameter(name = "level", description = "级别 0 市级，1镇级，3村级"),


    })
    @GetMapping("/getListManagement")
    @ResponseBody
    public AjaxResult getListManagement(
            @RequestParam(required = false) String listTypeSerialNumber,
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(defaultValue = "2") String level,
            @RequestParam(required = false) String search,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        return AjaxResult.success(changeBenefitPeopleService.getListManagement(listTypeSerialNumber, townNumber, villageNumber, level, search, pageNum, pageSize));
    }

    @Operation(summary = "村级事务-村级清单-详情")
    @Parameters({
            @Parameter(name = "listManagementSerialNumber", description = "清单ID"),

    })
    @GetMapping("/getListManagementDetail")
    @ResponseBody
    public AjaxResult getListManagementDetail(
            @RequestParam String listManagementSerialNumber
    ) {
        return AjaxResult.success(changeBenefitPeopleService.getListManagementDetail(listManagementSerialNumber));
    }

    @Operation(summary = "村级事务-村民积分")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
    })
    @GetMapping("/getPersonalPointsAccountList")
    @ResponseBody
    public AjaxResult getPersonalPointsAccountList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        return AjaxResult.success(changeBenefitPeopleService.getPersonalPointsAccountList(townNumber, villageNumber, pageNum, pageSize));
    }


    @Operation(summary = "村级事务-地图点位信息-图例")
    @Parameters({
            @Parameter(description = "标签序列号-非必填", name = "tagSerialNumber", required = false)
    })
    @GetMapping("/getAllBluePlateTags")
    @ResponseBody
    public AjaxResult getAllBluePlateTags(
            @RequestParam(required = false) @Parameter(description = "标签序列号") String tagSerialNumber
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getAllBluePlateTags(tagSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }


    @Operation(summary = "村级事务-地图点位信息")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
            @Parameter(description = "标签序列号-非必填", name = "tagSerialNumber", required = false)
    })
    @GetMapping("/getServiceResourcesCoordsList")
    @ResponseBody
    public AjaxResult getServiceResourcesCoordsList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) @Parameter(description = "标签序列号") String tagSerialNumber
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getServiceResourcesCoordsList(townNumber, villageNumber, tagSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据 粮地数据 作物类型 图例
     *
     * @return
     */
    @Operation(summary = "惠民数据 粮地数据 作物类型 图例 ")
    @GetMapping("/getCropCategory")
    @ResponseBody
    public AjaxResult getCropCategory(
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getCropCategory());
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据 粮地数据 地图数据列表
     *
     * @return
     */
    @Operation(summary = "惠民数据 粮地数据 作物类型 地图数据列表 ")
    @GetMapping("/getCropCategoryMapDataList")
    @ResponseBody
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必填"),
            @Parameter(name = "cropCategorySerialNumber", description = "作物类型序列号 非必填"),
    })
    public AjaxResult getCropCategoryMapDataList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
            ,@RequestParam(required = false) String cropCategorySerialNumber
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getCropCategoryMapDataList(townNumber, villageNumber,cropCategorySerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据 土地数据 土地类型 图例
     *
     * @return
     */
    @Operation(summary = "惠民数据 土地数据 土地类型 图例 ")
    @GetMapping("/getNatureResourceType")
    @ResponseBody
    public AjaxResult getNatureResourceType(
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getNatureResourceType());
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据 土地数据 土地类型 地图数据列表
     * @param townNumber
     * @param villageNumber
     * @param naturalResourceTypeSerialNumber
     * @return
     */
    @Operation(summary = "惠民数据 粮地数据 土地类型 地图数据列表 ")
    @GetMapping("/getNatureResourceMapDataList")
    @ResponseBody
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必填"),
            @Parameter(name = "naturalResourceTypeSerialNumber", description = "土地类型序列号 非必填"),
    })
    public AjaxResult getNatureResourceMapDataList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
            ,@RequestParam(required = false) String naturalResourceTypeSerialNumber
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getNatureResourceMapDataList(townNumber, villageNumber,naturalResourceTypeSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据 土地数据 补贴类型 图例
     *
     * @return
     */
    @Operation(summary = "惠民数据 土地数据 补贴类型 图例 ")
    @GetMapping("/getPolicyType")
    @ResponseBody
    public AjaxResult getPolicyType(
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getPolicyType());
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 惠民数据 土地数据 补贴类型 地图数据列表
     * @param townNumber
     * @param villageNumber
     * @param policyTypeSerialNumber
     * @return
     */
    @Operation(summary = "惠民数据 粮地数据 补贴类型 地图数据列表 ")
    @GetMapping("/getPolicyTypeMapDataList")
    @ResponseBody
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必填"),
            @Parameter(name = "policyTypeSerialNumber", description = "补贴类型序列号 非必填"),
    })
    public AjaxResult getPolicyTypeMapDataList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
            ,@RequestParam(required = false) String policyTypeSerialNumber
    ) {
        try {
            return AjaxResult.success(changeBenefitPeopleService.getPolicyTypeMapDataList(townNumber, villageNumber,policyTypeSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
}
